﻿using DFGK_WMS.IRepository;
using DFGK_WMS.Model.Models;
using DFGK_WMS.WebAPI.Controllers.Result;
using Microsoft.AspNetCore.Mvc;

namespace DFGK_WMS.WebAPI.Controllers.物料管理
{
    /// <summary>
    /// 物料报表
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TMaterialReportController : ControllerBase
    {
        private readonly ITMaterialReportRepository TMaterialReport;

        public TMaterialReportController(ITMaterialReportRepository TMaterialReport)
        {
            this.TMaterialReport = TMaterialReport;
        }


        /// <summary>
        /// 物料报表
        /// </summary>
        /// <param name="MaterialsName"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetMaterials(string? MaterialsName,string ? MaterialsCode, int pageIndex, int pageSize)
        {
            if (pageIndex <= 0 || pageSize <= 0)
            {
                return Ok(BaseResult.Result("400", "分页条件有误！"));
            }
            var list = TMaterialReport.GetMaterials(out var totalCount, MaterialsName,MaterialsCode, pageIndex, pageSize);
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", totalCount));

            }
            return Ok(BaseResult.Result(null, "查询失败！", "500", 0));
        }

        /// <summary>
        /// 进销存报表（出入库）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetInboundAndOutbound(string ? date, int pageIndex, int pageSize)
        {
            string message;
            if (pageIndex <= 0 || pageSize <= 0)
            {
                return Ok(BaseResult.Result("400", "分页条件有误！"));
            }
            var list = TMaterialReport.GetInboundAndOutbound(out var totalCount, out message, date, pageIndex, pageSize);
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200",totalCount));

            }
            return Ok(BaseResult.Result(null, message, "500",0));
        }

        ///进销存报表（出入库）
    }
}
